package huy.mmt.gamelathinh.dialog;

import huy.mmt.gamelathinh.Main;
import huy.mmt.gamelathinh.Play;
import huy.mmt.gamelathinh.R;
import huy.mmt.gamelathinh.components.Score;
import huy.mmt.gamelathinh.util.Util;
import huy.mmt.gamelathinh.util.UtilDialog;
import huy.mmt.gamelathinh.util.UtilFormat;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Sau má»—i láº§n vÆ°á»£t qua 1 level thÃ¬ dialog sáº½ Ä‘Æ°á»£c hiá»‡n thá»‹.
 * Dialog cho ta biáº¿t thá»�i gian hoÃ n thÃ nh level, sá»‘ sao vÃ  Ä‘iá»ƒm
 * thÆ°á»Ÿng
 * 
 * @author VAN GIOI
 * 
 */
public class DialogCompleted extends Dialog {
	Activity activity;
	static ImageView imageView_star1;
	static ImageView imageView_star2;
	ImageView imageView_star3;
	public static int star;
	public static int score_bonus2;

	/**
	 * 
	 * @param context
	 * @param timeend
	 *            : Dá»±a vÃ o time káº¿t thÃºc ta tÃ­nh Ä‘Æ°á»£c thá»�i gian
	 *            cÃ²n láº¡i vÃ  sá»‘ sao Ä‘áº¡t Ä‘Æ°á»£c
	 */
	public DialogCompleted(final Context context, int timeend) {
		super(context);
		UtilDialog.iniDialog(this);
		activity = (Activity) context;

		setContentView(R.layout.dialog_completed);

		// resize dialog
		LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayout_all);
		Util.resizeDialog(linearLayout);

		// button next
		Button button_next = (Button) findViewById(R.id.dialogcomplete_next);
		button_next.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Main.click.start();
				// Play.mPlay.showDialogPlay(1);
				DialogCompleted.this.dismiss();
				Play.newGame(Play.difficutly.getX(), Play.difficutly.getY());
				Play.txt_level.setText("Level:"
						+ String.valueOf(Play.level_current));
			}
		});
		// cancel to menu
		Button button_level = (Button) findViewById(R.id.dialogcomplete_menu);
		button_level.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Main.click.start();
				DialogCompleted.this.dismiss();
				Play.mPlay.finish();
			}
		});

		TextView textView_time = (TextView) findViewById(R.id.dialogcomplete_tv_timer);
		long tim = (240 * 1000 - Play.startTrunggian) / 1000;
		String mStringComplete = new String();
		mStringComplete = String.format("%02d", tim / 60) + ":"
				+ String.format("%02d", tim % 60);
		textView_time.setText(mStringComplete);

		imageView_star1 = (ImageView) findViewById(R.id.imageView_star1);
		imageView_star2 = (ImageView) findViewById(R.id.imageView_star2);
		imageView_star3 = (ImageView) findViewById(R.id.imageView_star3);
		getStart();
		getScoreBonus();
		TextView textView_bonus = (TextView) findViewById(R.id.textView_bonus);
		textView_bonus.setText("" + String.valueOf(score_bonus2));
	}

	public static int getStart() {
		long time_c = (240 * 1000 - Play.startTrunggian) / 1000;

		if (time_c >= 90) {
			star = 1;
		}
		if (60 < time_c && time_c < 90) {
			star = 2;
		}
		if (0 <= time_c && time_c <= 60) {
			star = 3;
		}
		return star;
	}

	public static void getScoreBonus() {
		if (star == 1) {
			// an di 2 sao
			imageView_star1.setVisibility(View.GONE);
			imageView_star2.setVisibility(View.GONE);
			// / tinh score +
			score_bonus2 = 500;
		}
		if (star == 2) {
			// an di sao
			imageView_star1.setVisibility(View.GONE);
			score_bonus2 = 1000;
		}
		if (star == 3) { // an di 2 sao
			score_bonus2 = 1500;
		}
	}
	// set text score_bonuss

}